package com.haotunet.app.goldtreasure.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.model.ProfitInfo;
import com.haotunet.app.goldtreasure.views.HorizontalProgressBar;

import java.util.List;

public class ProfitAdapter extends HolderAdapter<ProfitInfo, ProfitAdapter.ViewHolder> {

	public ProfitAdapter(Context context, List<ProfitInfo> list) {
		super(context, list);
	}

	public static class ViewHolder {
		HorizontalProgressBar progressBar;
		TextView tvTime;
		TextView tvProfit;
	}

	@Override
	public View buildConvertView(LayoutInflater layoutInflater, ProfitInfo t, int position) {

		return inflate(R.layout.item_profit);
	}

	@Override
	public ViewHolder buildHolder(View convertView, ProfitInfo t, int position) {
		ViewHolder holder = new ViewHolder();
		holder.progressBar = (HorizontalProgressBar) convertView.findViewById(R.id.pgsBar);
		holder.tvProfit = (TextView) convertView.findViewById(R.id.txt_profit);
		holder.tvTime = (TextView) convertView.findViewById(R.id.txt_time);
		return holder;
	}

	@Override
	public void bindViewDatas(View convertView, ViewHolder holder, ProfitInfo profitInfo, int position) {
		if (position == 0) {
			holder.progressBar.setProgressDrawable(context.getResources().getDrawable(R.drawable.progressbar));
		} else {
			holder.progressBar.setProgressDrawable(context.getResources().getDrawable(R.drawable.progressbar_gray));
		}
		String percent = profitInfo.getPercent();
		String income_quantity = profitInfo.getIncomeMass();
		String income_time = profitInfo.getIncomeTime();
		holder.tvTime.setText(income_time);
		holder.progressBar.setProgress((int) ((Double.parseDouble(percent)) * 100));
		holder.progressBar.setValue(income_quantity, ((Double.parseDouble(percent))));

	}
}
